<?php
class AutoTimestampBehavior extends CActiveRecordBehavior {
    /**
    * The field that stores the creation time
    */
    public $create_time = 'create_time';
    /**
    * The field that stores the modification time
    */
    public $update_time = 'update_time';
 
    public function beforeValidate($on) {
        if ($this->Owner->isNewRecord)
            $this->Owner->{$this->create_time} = new CDbExpression('NOW()');
        else
            $this->Owner->{$this->update_time} = new CDbExpression('NOW()');
 
        return true;    
    }
}